/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.wiim.rpi;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.wiringpi.SoftPwm;
import sun.reflect.generics.tree.Tree;

/**
 *
 * @author wimvandecasteele
 */
public class LED {
       
    private final GpioController fGpioController = GpioFactory.getInstance();  
    private GpioPinDigitalOutput fLED = null;

    public LED() {
            fLED = fGpioController.provisionDigitalOutputPin(RaspiPin.GPIO_01, "LED", PinState.LOW);  
    }
    
    public void doSomething() throws InterruptedException
    {
        //fLED.high();
        //Thread.sleep(2000);
        //fLED.low();
        //Thread.sleep(1000);
        //fLED.blink(500,3000);
        //fLED.toggle();
        //fGpioController.shutdown();
    }
    
    public void fakePWM() throws InterruptedException
    {
       SoftPwm.softPwmCreate(1, 0, 100);
        while (true) {            
            // fade LED to fully ON
            for (int i = 0; i <= 90; i++) {
                SoftPwm.softPwmWrite(1, i);
                Thread.sleep(50);
            }

            // fade LED to fully OFF
            for (int i = 90; i >= 0; i--) {
                SoftPwm.softPwmWrite(1, i);
                Thread.sleep(50);
            }
        }
    }
}
